<template>
  <a-layout id="baseLayout">
    <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
      <div class="logo">
        <div v-if="collapsed">FNIU</div>
        <div v-else>FNIU博客后台</div>
      </div>
      <a-menu theme="dark" mode="inline" :default-selected-keys="[$route.path]" @click="menuClick">
        <a-sub-menu key="sub1">
          <span slot="title"><a-icon type="mail" /><span>我的</span></span>

          <a-menu-item key="/user/info"> 我的信息 </a-menu-item>
          <a-menu-item key="/user/skill"> 我的技能 </a-menu-item>
          <a-menu-item key="/user/exp"> 我的经验 </a-menu-item>
        </a-sub-menu>

        <a-menu-item key="/type">
          <a-icon type="video-camera" />
          <span>类型</span>
        </a-menu-item>
        <a-menu-item key="/blog">
          <a-icon type="upload" />
          <span>博客</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header class="layout-header">
        <div>
          <a-icon class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="() => (collapsed = !collapsed)" />
          <!-- <a-tag color="#f50"> 欢迎来带FNIU博客后台!我的朋友 </a-tag> -->
        </div>
        <div class="avatar" v-if="userInfo">
          <a-avatar shape="square" icon="user" />
          {{ userInfo.name }}
        </div>
      </a-layout-header>
      <a-layout-content :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px', overflow: 'auto' }">
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>
export default {
  data() {
    return {
      collapsed: false,
      userInfo: null
    }
  },

  created() {
    this.$api.user().then(res => {
      if(res.code === 1) {
        this.userInfo = res.data
      } else {
        localStorage.removeItem('_token')
      }
    })
  },

  methods: {
    menuClick({ key }) {
      this.$router.push({
        path: key
      })
    }
  }
}
</script>
<style lang="less">
#baseLayout {
  height: 100%;
  position: relative;
  z-index: 2;
  .trigger {
    font-size: 18px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color 0.3s;
    &:hover {
      color: #1890ff;
    }
  }

  .logo {
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    margin: 16px;
    color: #fff;
  }

  .layout-header {
    padding-right: 50px;
    padding-left: 0;
    background: #fff;
    display: flex;
    justify-content: space-between;
  }

  .avatar {
    background: #f0f2f5;
    padding: 0 20px;
    .ant-avatar {
      margin-right: 10px;
    }
  }
}
</style>